const { SnapshotManager } = require("./utils/snapshot")

App({
  onLaunch() {
    // wx.cloud.init({
    //   env: 'cloud1-5gigqqu3da01a065',
    //   traceUser: true
    // })
  },

  globalData: {
    userInfo: null
  },

  // 创建事件总线
  eventBus: {
    callbacks: {},

    on(eventName, callback) {
      if (!this.callbacks[eventName]) {
        this.callbacks[eventName] = []
      }
      this.callbacks[eventName].push(callback)
    },

    emit(eventName, data) {
      const callbacks = this.callbacks[eventName]
      if (callbacks) {
        callbacks.forEach(cb => cb(data))
      }
    },

    off(eventName, eventHandler) {
      if (eventHandler) {
        let index = this.callback[eventName].findIndex(e => e === eventHandler)
        this.callback[eventName].splice(index, 1)
        return
      }
      delete this.callbacks[eventName]
    },

    hasEventName(eventName) {
      return this.callbacks[eventName] && this.callbacks[eventName].length > 0
    }
  }
})